function toThousands(number: number) {
  let num = (number || 0).toString();
  let result = '';
  while (num.length > 3) {
    result = ',' + num.slice(-3) + result;
    num = num.slice(0, num.length - 3);
  }
  if (num) {
    result = num + result;
  }
  return result;
}

function getCookie(cookieName: string) {
  let value;
  const allCookies = document.cookie;
  let cookiePos = allCookies.indexOf(cookieName);
  if (cookiePos != -1) {
    cookiePos = cookiePos + cookieName.length + 1;
    let cookieEnd = allCookies.indexOf(';', cookiePos);

    if (cookieEnd == -1) {
      cookieEnd = allCookies.length;
    }

    value = unescape(allCookies.substring(cookiePos, cookieEnd));
  }

  return value;
}

function getCurrentFormattedTime() {
  const daysOfWeek = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0');
  const day = String(now.getDate()).padStart(2, '0');
  const hours = String(now.getHours()).padStart(2, '0');
  const minutes = String(now.getMinutes()).padStart(2, '0');
  const seconds = String(now.getSeconds()).padStart(2, '0');
  const dayOfWeek = daysOfWeek[now.getDay()];
  return `${year}年${month}月${day}日${hours}:${minutes}:${seconds} ${dayOfWeek}`;
}

/**根据窗口的大小来更改字体的大小 */
const getFontSize = (font_size: number) => {
  const width = window.innerWidth;
  const fontSize = width / 1920 * font_size;
  return fontSize;
}

export { toThousands, getCookie, getCurrentFormattedTime, getFontSize };
